﻿var bShowStatusOnRefresh = false;
var strStatusMessage;
var strStatusTitle = "Copy Item:";

function SPRACopyItemEnable() {
    var items = SP.ListOperation.Selection.getSelectedItems();
    var itemCount = CountDictionary(items);

    return (itemCount == 1);
}

function SPRACopyItemDialogCallback(dialogResult, returnValue){
    SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);

    strStatusMessage = "Successfully created item copy.";
    bShowStatusOnRefresh = true;
}


function SPRACopyItemShowDialog(SiteUrl, ItemId, ListId, Source) {
    var items = SP.ListOperation.Selection.getSelectedItems(); 
    var selectedItems = ''; 
    var i; 
    for (i in items) 
    { 
        selectedItems += '|' + items[i].id; 
    }
    var options = {
        url: SiteUrl + '/_layouts/SPRA/CopyItem.aspx?ID=' + ItemId + '&List=' + ListId + '&SelectedItems=' + selectedItems + '&Source=' + Source,
        allowMaximize: true,
        showClose: false,
        dialogReturnValueCallback: SPRACopyItemDialogCallback
    };

    SP.UI.ModalDialog.showModalDialog(options);
}

if (bShowStatusOnRefresh) {
    this.statusID = SP.UI.Status.addStatus(strStatusTitle, strStatusMessage, true);
    SP.UI.Status.setStatusPriColor(this.statusID, "green");
}